Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 1 - Introducing AppleScript
Chapter 2 - Overview of AppleScript


Commands and Objects

Commands are the words or phrases you use in AppleScript statements to request actions or results. Every command is directed at a target, which is
the object that responds to the command. The target of a command is usually an application object. Application objects are objects that belong to an application, such as windows, or objects in documents, such as the words
and paragraphs in a text document. Each application object has specific information associated with it and can respond to specific commands.

For example, in the Scriptable Text Editor, window objects understand the Print command. The following example shows how to use the Print command to request that the Scriptable Text Editor print the front window.

tell application "Scriptable Text Editor"   print front window
end tell
The Print command is contained within a Tell statement. Tell statements specify default targets for the commands they contain. The default target is the object that receives commands if no other object is specified or if the object is specified incompletely in the command. In this case, the statement containing the Print statement does not contain enough information to uniquely identify the window object, so AppleScript uses the application name listed in the Tell statement to determine which object receives the Print command.

In AppleScript, you use references to identify objects. A reference is a compound name, similar to a pathname or address, that specifies an object.
For example, the following phrase is a reference:

front window of application "Scriptable Text Editor"
This phrase specifies a window object that belongs to a specific application. (The application itself is also an object.) AppleScript has different types of references that allow you to specify objects in many different ways. You'll learn more about references in Chapter 5, "Objects and References."

Objects can contain other objects, called elements. In the previous example, the front window is an element of the Scriptable Text Editor application object. Similarly, in the next example, a word element is contained in a specific paragraph element, which is contained in a specific document.

word 1 of paragraph 3 of document "Try This"
Every object belongs to an object class, which is simply a name for objects with similar characteristics. Among the characteristics that are the same for the objects in a class are the commands that can act on the objects and the elements they can contain. An example of an object class is the Document object class in the Scriptable Text Editor. Every document created by the Script Editor belongs to the Document object class. The Script Editor's definition of the document object class determines which classes of elements, such as paragraphs and words, a document object can contain. The definition also determines which commands, such as the Close command, a document object can respond to.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996